<template>
  <div>
    <el-menu>
      <el-submenu v-for="state in 4" :key="state" :index="state.toString()">
        <template slot="title">
          <div class="stateName">
            {{ state | StateToName }}
          </div>
        </template>
        <el-menu-item
          v-for="itme in getToDoList(state)"
          :key="itme.createTime"
          :index="itme.createTime.toString()"
          @click="onSelectTodoItme(itme)"
        >
          {{ itme | TodoName }}
        </el-menu-item>
      </el-submenu>
    </el-menu>
  </div>
</template>

<script lang="ts">
import { SetCurrentTodo, Todo, TODOState } from "@/types";
import Vue from "vue";
import { mapState } from "vuex";
export default Vue.extend({
  name: "Navigation",
  props: {
    ...mapState(["todoList"]),
  },
  methods: {
    getToDoList(state: TODOState) {
      let list: Todo[] = this.$store.state.todoList;
      let result = list?.filter((x) => x.state == state);
      return result;
    },
    onSelectTodoItme(item: Todo) {
      this.$store.commit(SetCurrentTodo, item);
    },
  },
});
</script>

<style scoped>
.stateName {
  margin-left: 30px;
  text-align: left;
}
</style>
